![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
A standalone FAT16/FAT32 implementation that takes in a block-access interface and exposes something quite similar to require('fs')
(i.e. the node.js built-in Filesystem API).
npm install fatfs
var fatfs = require('fatfs'),
fs = fatfs.createFileSystem(exampleDriver); // see below
fs.stat("autoexec.bat", function (e,stats) {
if (e) console.error(e);
else console.log(stats);
});
// TODO: open a file and write to it or something…
fs = fatfs.createFileSystem(vol, [opts], [cb])
— Simply pass in a block driver (see below) mapped to a FAT partition somewhere, and get back the API documented here. An options dictionary can be provided, details are in the next section. You may also optionally provide a callback cb(err)
which will be automatically registered for the on 'ready'
or 'error'
event.'ready'
event — fired on fs
when initial volume information has been determined and the API is ready to use. It is safe to call other fs
methods before this fires only if you are sure the first sector will be readable and represents a valid FAT volume.'error'
event — fired if initialization fails for whatever reason.The opts
dictionary you pass to fatfs.createFileSystem
can contain any of the following options:
ro
— Enables readonly mode if true
. It defaults to false
, but if your volume driver does not provide a writeSectors
method it will be overriden to true
.noatime
— The FAT filesystem can track the last access time (just a date, actually) but this means every read operation would also incur some write overhead. Defaults to true
, meaning by default access times will not be updated on reads. Set this to false
to track access times.modmode
— chooses how fs.chmod
(and the mode field from fs.stat
–family calls) should map FAT attributes to POSIX permissions. Set to the number 0111
to map the readonly flag to the user's write bit being unset, and the archive/system/hidden flags to the user/group/other executable bits respectively. Set to the number 07000
to map the readonly flag to all write bits being unset, and the archive/system/hidden flags to the sticky/setgid/setuid bits respectively. Set to null
for readonly mapping. Defaults to 0111
.umask
— any bits set in this octal number will be unset in the 'mode' field from fs.stat
–family calls. It does not affect anything else. Defaults to process.umask()
, or 0022
if that is unavailable.uid
— This value will be returned as the 'uid' stat field. It does not affect anything else. Defaults to process.getuid()
, or 0
if that is unavailable.gid
— This value will be returned as the 'gid' stat field. It does not affect anything else. Defaults to process.getgid()
, or 0
if that is unavailable.(Note that these are similar to the options you could use with a POSIX mount
operation.)
And that's it! The rest of the API (fs.readdir
, fs.open
, fs.createReadStream
, fs.appendFile
, etc.) is as documented by the node.js project.
Well, sort of…
fs.rename
, fs.unlink
and fs.rmdir
, as well as fs.watchFile
/fs.unwatchFile
and fs.watch
. These are Coming Soon™.Some of the differences between fatfs
and the node.js fs
module are "by design" for architectural simplicity and/or due to underlying FAT limitations.
fs.*Sync
methods. (The volume driver is async, not to mention that supporting a separate *Sync codepath would be an enormous duplication of effort of dubious value.)createFileSystem
instances for multiple volumes; paths are relative to each, and don't share a namespace.To use 'fatfs', you must provide a driver object with the following properties/methods:
driver.sectorSize
— number of bytes per sector on this devicedriver.numSectors
— count of sectors available on this mediadriver.readSectors(i, dest, cb)
— Fill dest
with data starting at the i
th sector and notify cb(e)
when finished. You may assume dest.length
is a multiple of driver.sectorSize
.driver.writeSectors(i, data, cb)
— (optional) Write data
starting at the i
th sector and notify cb(e)
when finished. You may assume data.length
is a multiple of driver.sectorSize
.If you do not provide a writeSectors
method, then fatfs
will work in readonly mode. Pretty simple, eh? And the 'fatfs' module makes a good effort to check the parameters passed to your driver methods!
TBD: to facilitate proper cache handling, this module might add an optional driver.flush(cb)
method at some point in the future.
Here's an example taken from code used to run this module's own tests:
// NOTE: this assumes image at `path` has no partition table.
// If it did, you'd need to translate positions, natch…
var fs = require('fs');
exports.createDriverSync = function (path, opts) {
opts || (opts = {});
var secSize = 512,
ro = opts.readOnly || false,
fd = fs.openSync(path, (ro) ? 'r' : 'r+'),
s = fs.fstatSync(fd);
return {
sectorSize: secSize,
numSectors: s.size / secSize,
readSectors: function (i, dest, cb) {
if (dest.length % secSize) throw Error("Unexpected buffer length!");
fs.read(fd, dest, 0, dest.length, i*secSize, function (e,n,d) {
cb(e,d);
});
},
writeSectors: (ro) ? null : function (i, data, cb) {
if (data.length % secSize) throw Error("Unexpected buffer length!");
fs.write(fd, data, 0, data.length, i*secSize, function (e) {
cb(e);
});
}
};
};
© 2014 Nathan Vander Wilt. Funding for this work was provided by Technical Machine, Inc.
Reuse under your choice of:
FAQs
fs implementation on top of raw FAT16/FAT32 block source
We found that fatfs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.